
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Gateway中的Filter机制 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Gateway中的Filter机制 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">Spring Cloud Gateway的Filter机制采用了什么设计模式？它将过滤器分为哪两类，各自在何时执行？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它采用的是基于过滤器链的设计模式。过滤器分为两类：Pre Filter 和 Post Filter。Pre Filter 在请求被路由之前执行，用于处理请求的初始逻辑；Post Filter 在请求被路由之后执行，用于处理响应数据。</div>
          </div>
          <div class="card-source">来源: Gateway Filter 机制的概述</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Gateway Filter的执行顺序是如何控制的？并且在Pre阶段和Post阶段的执行顺序有何不同？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">过滤器的执行顺序通过 `Order` 属性控制，值越小优先级越高。在 Pre 阶段，过滤器按 `Order` 值的升序执行；而在 Post 阶段，过滤器按降序执行。</div>
          </div>
          <div class="card-source">来源: Gateway Filter 的工作原理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Gateway Filter机制基于什么编程模型？该模型带来了哪些核心优势？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它基于WebFlux的响应式编程模型。该模型采用非阻塞的方式处理高并发请求，优势在于具备更高的性能和更低的资源占用，适合高并发场景。</div>
          </div>
          <div class="card-source">来源: Gateway Filter 机制的概述</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">全局过滤器（Global Filters）和局部过滤器（Route-Specific Filters）的核心区别是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">核心区别在于作用范围。全局过滤器作用于所有请求，不与特定路由绑定，适用于认证、日志记录等通用逻辑。局部过滤器则绑定到特定路由规则，仅对匹配该路由的请求生效，适用于针对单一服务的定制化处理。</div>
          </div>
          <div class="card-source">来源: Gateway Filter 的工作原理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">请列举三个Spring Cloud Gateway提供的内置过滤器及其主要功能。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. `RewritePath`：通过正则表达式修改请求路径，以适配目标服务的API规范。<br>2. `RequestRateLimiter`：基于Redis的令牌桶算法对请求实施限流控制。<br>3. `CircuitBreaker`：实现断路器模式，监控并快速失败不稳定的请求，防止连锁反应。</div>
          </div>
          <div class="card-source">来源: Gateway Filter 的内置过滤器</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">实现一个自定义的全局过滤器（Global Filter）需要实现哪两个核心接口？它们分别起什么作用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">需要实现 `GlobalFilter` 接口和 `Ordered` 接口。`GlobalFilter` 接口用于定义核心的过滤逻辑，而 `Ordered` 接口用于控制该过滤器的执行顺序。</div>
          </div>
          <div class="card-source">来源: 自定义过滤器的实现步骤</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">应用</div>
          <div class="card-question">在微服务架构中，Gateway Filter如何应用于“请求认证与鉴权”场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">应用</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在请求认证与鉴权场景中，过滤器可以作为进入服务的第一道关卡。它可以在Pre阶段验证请求是否携带有效的Token（如JWT），检查API请求的认证信息，或根据用户角色权限决定是否允许访问目标服务。</div>
          </div>
          <div class="card-source">来源: Gateway Filter 的应用场景</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">应用</div>
          <div class="card-question">Gateway Filter如何支持灰度发布或A/B测试这类动态流量管理场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">应用</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">过滤器可以通过动态调整流量分配策略来支持灰度发布。例如，它可以根据请求头信息或按一定比例（如10%的流量）将部分请求转发到新版本的服务实例，而其余请求仍访问旧版本服务，从而实现动态流量管理。</div>
          </div>
          <div class="card-source">来源: Gateway Filter 的应用场景</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">尽管Gateway Filter采用异步非阻塞模型性能很高，但在开发和调试方面存在哪些主要缺点？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">主要缺点包括：<br>1. 开发复杂性较高：需要熟悉Reactive编程模型，复杂逻辑可能导致代码难以维护。<br>2. 调试和监控困难：Reactive编程导致请求链路难以直接跟踪，需要借助Zipkin等额外工具，增加了运维复杂度。<br>3. 学习成本较高：初学者需要理解WebFlux和响应式编程理念。</div>
          </div>
          <div class="card-source">来源: Gateway Filter 的优缺点</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
